/*
 * 6.1.cpp
 *
 *  Created on: 2012-5-18
 *      Author: jawinton
 */

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

#define SIZE 300

int n, m;
bool monkeys[SIZE+10];

int nextPt (int cur) {
	while (monkeys[cur] == false) cur = (cur+1)%n;
	cur = (cur+1)%n;
	return cur;
}

int main (void) {
	while (true) {
		cin >> n >> m;
		if (n == 0) break;
		for (int i=0; i<n; i++) monkeys[i] = true;
		//int nPt = -1;
		int nPt = 0;
		for (int i=0; i<n; i++) {
			int nCount = 0;
			while (nCount < m) {
				nPt = nextPt(nPt);
				nCount ++;
			}
			nPt --;
			if (nPt == -1) nPt = n-1;
			if (i == n-1) cout << nPt+1 << endl;
			monkeys[nPt] = false;
		}
	}
	return 0;
}
